package cc.rengu.igas.share.facade.bean.cups;

import cc.rengu.oltp.service.common.enums.OltpRpcdEnum;
import cc.rengu.oltp.service.model.BizException;

import java.util.Arrays;

/**
 * F3 MTI 交易处理码  (未选卡种) 场景
 *
 * @author fangminwei
 * @date 2021/4/17
 */
@SuppressWarnings("AlibabaEnumConstantsMustHaveComment")
public enum F3_ProcessingCodeEnum {
    _300000("300000", "余额查询"),
    _030000("030000", "预授权/预授权冲正"),
    /**
     * 退款
     * _200000("200000","预授权撤销/预授权撤销冲正"),
     * _200000("200000","授权撤销/MOTO预授权撤销/冲正"),
     * _200000("200000","消费撤销/MOTO消费撤销/代收撤销/冲正"),
     * _200000("200000","预授权完成撤销/冲正"),
     * _200000("200000","退货"),
     */
    _200000("200000", "退款类"),
    /**
     * 借记
     * _000000("000000","预授权完成（请求）/冲正/退单/再请款"),
     * _000000("000000","授权/MOTO预授权/冲正"),
     * _000000("000000","消费/脱机消费通知/MOTO消费/代收/冲正/退单/再请款"),
     * _000000("000000","预授权完成（请求、通知）/结算通知/手工预授权完成/MOTO预授权完成（请求、通知）/MOTO结算通知/退单/再请款"),
     */
    _000000("000000", "借记类"),
    /**
     * 现金
     * _010000("010000","取现/冲正/退单/再请款/预借现金"),
     * _010000("010000","预借现金冲正"),
     */
    _010000("010000", "现金类"),
    /**
     * 存款
     * _210000("210000","存款"),
     * _210000("210000","存款确认"),
     */
    _210000("210000", "存款/存款确认"),
    /**
     * 调整
     * _220000("220000","贷记调整"),
     * _220000("220000","差错例外"),
     */
    _220000("220000", "调整"),
    _170000("170000", "存款撤销/IC卡电子现金应用的现金充值撤销/冲正"),
    _400000("400000", "转账（转入方付费、转出方付费）"),
    _460000("460000", "转出（转入方付费、转出方付费）/冲正"),
    /**
     * 转入
     * _470000("470000","转入确认（转入方付费、转出方付费）"),
     */
    _470000("470000", "转入（转入方付费、转出方付费）/转入确认（转入方付费、转出方付费）"),
    _020000("020000", "请款/退单/再请款"),
    _600000("600000", "基于UICS的IC卡电子现金应用指定账户圈存"),
    _620000("620000", "基于UICS的IC卡电子现金应用的非指定账户转账圈存/冲正"),
    _630000("630000", "基于UICS的IC卡电子现金应用的现金充值/冲正、磁条卡现金充值/充值确认"),
    _640000("640000", "基于UICS的IC卡电子现金应用的非指定账户转出圈存/冲正"),
    _650000("650000", "基于UICS的IC卡电子现金应用的非指定账户转入圈存"),
    _190000("190000", "收/付费-借记"),
    _270000("270000", "预借现金（CashAdvance）撤销"),
    _240000("240000", "汇款验证/汇款/手工汇款"),
    /**
     * 贷记
     * _290000("290000","收/付费-贷记"),
     */
    _290000("290000", "贷记/贷记确认"),
    _330000("330000", "账户验证"),
    _890000("890000", "建立委托/冲正"),
    _920000("920000", "解除委托/冲正"),
    _930000("930000", "代授权交易联机传输通知"),
    ;

    private String code;
    private String desc;

    F3_ProcessingCodeEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public String getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    @Override
    public String toString() {
        return code + "-" + desc;
    }

    public static F3_ProcessingCodeEnum find(String code) {
        F3_ProcessingCodeEnum result = Arrays.stream(F3_ProcessingCodeEnum.values())
                .filter(e -> e.getCode().equals(code)).findFirst().orElse(null);

        if (result == null) {
            throw new BizException(OltpRpcdEnum.PARAM_IS_EMPTY_OR_NULL.getRespCode(), "找不到对应的枚举信息" + code);
        }
        return result;
    }

    /**
     * 存款/存款确认交易 交易类型(3域前两位) 21
     */
    private static final String F3_DEPOSIT = "21";
    /**
     * 存款撤销交易 交易类型(3域前两位) 17
     */
    private static final String F3_DEPOSIT_CANCEL = "17";
    /**
     * 转入/转入确认交易 交易类型(3域前两位) 47
     */
    private static final String F3_TRANS_IN = "47";
    /**
     * 汇款交易 交易类型(3域前两位) 24
     */
    private static final String F3_REMITTANCE = "24";
    /**
     * 贷记/贷记确认交易 交易类型(3域前两位) 29
     */
    private static final String F3_CREDIRT = "29";


    /**
     * 域3 交易处理码  1-2位表示交易类型
     * 21-存款/存款确认
     * 17-存款撤销
     * 47-转入（转入方付费、转出方付费）/转入确认（转入方付费、转出方付费）
     * 24-汇款验证/汇款/手工汇款
     * 29-贷记/贷记确认
     *
     * @return Boolean
     * @author wxb
     */
    public static boolean isCreditTrans(String code) {
        return F3_DEPOSIT.equals(code.substring(0, 2)) ||
                F3_DEPOSIT_CANCEL.equals(code.substring(0, 2)) ||
                F3_TRANS_IN.equals(code.substring(0, 2)) ||
                F3_REMITTANCE.equals(code.substring(0, 2)) ||
                F3_CREDIRT.equals(code.substring(0, 2));
    }

}
